package com.k1998.mybatis.controller;


import com.k1998.mybatis.bean.*;
import com.k1998.mybatis.dao.IJxCloudDao;
import com.k1998.mybatis.service.JxCloudService;
import com.k1998.mybatis.utils.BatchInfo;
import com.k1998.mybatis.utils.HashMapUtils;
import com.k1998.mybatis.utils.JxUtils;
import com.k1998.mybatis.utils.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(value = "计协官网资源Api文档" , tags = {"计协官网资源Api文档"})
public class JxCloudController {
    @Autowired
    private  JxCloudService jxCloudService;
    @Autowired
    private IJxCloudDao iJxCloudDao;

    @PostMapping("/allJxCloud")
    @ApiOperation(value = "筛选查询资源", notes="筛选查询资源")
    public String getAll(@RequestBody QueryInfo queryInfo) {
        return jxCloudService.getAllJxClouds(queryInfo);
    }

    @PostMapping("/detailJxCloud")
    @ApiOperation(value = "详细查询", notes="详细查询", httpMethod = "POST")
    public String detailJxCloud(@RequestBody JxCloud jx){
        return HashMapUtils.toHashMap(iJxCloudDao.detailJxCloud(jx));
    }

    @PostMapping("/insertJxCloud")
    @ApiOperation(value = "添加计协资源信息", notes="添加计协资源信息", httpMethod = "POST")
    public String insertJxCloud(@RequestBody JxCloud jx){
        return iJxCloudDao.insertJxCloud(jx)>0 ? "success" : "error";
    }

    @PostMapping("/updateJxCloud")
    @ApiOperation(value = "修改计协资源信息", notes="修改计协资源信息", httpMethod = "POST")
    public String updateJxCloud(@RequestBody JxCloud jx){
        return iJxCloudDao.updateJxCloud(jx)>0 ? "success" : "error";
    }

    @PostMapping(value = "batchDeleteJxCloud")
    @ApiOperation(value = "批量删除资源信息" , notes="批量删除资源信息" , httpMethod = "POST")
    public String batchDeleteJxCloud(@RequestBody BatchInfo info){
        List<String> list= JxUtils.stringToList(info.getIds());
        if(null==list){return "error";}
        iJxCloudDao.batchDeleteJxCloud(list);
        return "success";
    }

    @PostMapping(value = "batchReversDisplayJxcloud")
    @ApiOperation(value = "批量设置展示反选",notes = "批量设置展示反选",httpMethod = "POST")
    public String batchReversDisplayJxcloud(@RequestBody BatchInfo info){
        List<String> list= JxUtils.stringToList(info.getIds());
        if(null==list){return "error";}
        iJxCloudDao.reversDisplayJxcloud(list);
        return "success";
    }
}
